package com.example.novelweb.utils;

import cn.hutool.core.util.StrUtil;
import com.example.novelweb.constant.RegexPatterns;


public class RegexUtils {

  // mismatch 失配
  private static boolean mismatch(String str,String regex) {
    if(StrUtil.isBlank(str)) {
      return true;
    }
    return !str.matches(regex);
  }

  /**
   * @return true: 非法, false:合法
   * */
  public static boolean isPhoneInvalid(String phone) {
    return mismatch(phone, RegexPatterns.PHONE_REGEX);
  }
  public static boolean isCodeInvalid(String code) {
    return mismatch(code,RegexPatterns.VERIFY_CODE_REGEX);
  }

  public static boolean isListStrInvalid(String list) {
    return mismatch(list,RegexPatterns.ID_STRING_REGEX);
  }
}


